package com.example.bawolf.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collector;

/**
 * @author zhougf
 * @version 1.0
 * @date 2020/06/09
 */
public class StreamTest {
    static class Person {
        private String name;
        private int age;

        public Person(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

    public static void main(String[] args) {
        Person bai = new Person("bai", 20);
        Person zhou = new Person("zhou", 21);
        List<Person> personList = Arrays.asList(bai, zhou);
        List<String> nameList = new ArrayList<>();
        Function<Person, List<String>> function = x -> {
            nameList.add(x.getName());
          return  nameList;
        };
        function.apply(bai);
        function.apply(zhou);
        System.out.println(nameList);
        //biconsumer使用
//        BiConsumer<Person, List<String>> biConsumer = (p, list) -> {
//            list.add(p.getName());
//        };
//        List<String> nameList = new ArrayList<>();
//        biConsumer.accept(bai, nameList);
//        biConsumer.accept(bai, nameList);
//        System.out.println(nameList);
        //消费器使用
//        Consumer<Person> consumer = x -> {
//            System.out.println(x.getName());
//        };
//        consumer.accept(zhou);
////        personList.forEach(consumer);
        //收集器使用 1.容器也就是要的类型， 2.操作， 3.分片合并操作 ，5.并发处理相关
//        List<String> nameList = personList.stream().collect(Collector.of(ArrayList::new, (sup, s) -> sup.add(s.getName()), (left, right) -> {
//            left.addAll(right); return left; }, Collector.Characteristics.IDENTITY_FINISH));
//        System.out.println(nameList);
    }
}
